import { EggAppConfig, EggAppInfo, PowerPartial } from 'egg';

export default (appInfo: EggAppInfo) => {
  const config = exports = {} as PowerPartial<EggAppConfig>;

  // override config from framework / plugin
  // use for cookie sign key, should change to your own and keep security
  config.keys = appInfo.name + '_1618801551785_9466';

  // plugins
  exports.view = {
    mapping: {
      '.ejs': 'ejs',
    },
    defaultMapping: '.ejs'
  };
  exports.mongoose = {
    client: {
      url: 'mongodb://deanros.com:27017/xgtest',
      options: {
        authSource: 'admin',
        auth: {
          user: 'xg',
          password: 'xg123456',
        },
        useUnifiedTopology: true,
      },
    },
  };
  exports.redis = {
    client: {
      port: 6379,          // Redis port
      host: 'deanros.com',   // Redis host
      password: '1qaz!QAZ',
      db: 4,
    },
  };
  exports.zipCode = {
    path: __dirname + '/tmp'
  };

  config.security = {
    csrf: {
      // enable: false,
      headerName: 'x-csrf-token',
    }
  };
  // add your egg config in here
  config.middleware = [];

  // add your special config in here
  const bizConfig = {
    sourceUrl: `https://github.com/eggjs/examples/tree/master/${appInfo.name}`,
  };

  // the return config will combines to EggAppConfig
  return {
    ...config,
    ...bizConfig,
  };
};
